-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Introduce Scope::NonGlobModule and Scope::GlobModule #144131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
f1097bc
to
c3185be
Compare
resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like rust-lang#144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like rust-lang#144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like rust-lang#144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like rust-lang#144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
Rollup merge of #144368 - petrochenkov:rmrootscope, r=b-naber resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like #144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
This comment was marked as resolved.
This comment was marked as resolved.
resolve: Remove `Scope::CrateRoot` Use `Scope::Module` with the crate root module inside instead, which should be identical. This is a simplification by itself, but it will be even larger simplification if something like rust-lang/rust#144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs). I also did some renamings for consistency: - `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude` - `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude` - `is_absolute_path` -> `module_and_extern_prelude`
c3185be
to
9c0ee44
Compare
@petrochenkov do you have time to review this in the next couple of days? |
Probably after #144579, this is low priority for me. |
I figured, I'll just re-roll then. r? @rust-lang/compiler |
I still need to look, this is an important part of the resolve infrastructure. |
Other maintainers are also qualified to review this code. PR writers are allowed to re-roll reviewers after 2 weeks of inactivity; the fact that you just ignore this is kind of wild. |
Vadim is the foremost expert on name resolution in the compiler, and if he wants to take a look at the PR, that is completely fine. No one is taking away your option of rerolling, but that doesn't mean that you get to choose the only reviewer. If there are other people with concerns or comments, their input also has to be taken into account, regardless of whether they are the currently assigned reviewer or not. |
(Btw you just pinged the entire compiler team, more than 50 people. The way to re-roll is |
I understand, but there must be some limit for how long someone can request to take a look at a PR; if the PR has low priority for the maintainer requesting a review, at some point there should still be a way to get this merged in a reasonable amount of time. Now obviously 2 weeks isn't anywhere close to such a limit, so I apologize for overreacting here. |
I'm certainly going to review this in some time. |
#144793 splits extern prelude into two scopes and demonstrates some things that need to be done for the module scope split as well.
|
non_glob_module_inserted = true; | ||
} | ||
Scope::GlobModule(module, _) => { | ||
if !non_glob_module_inserted { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non_glob_module_inserted
will always be true as written.
self.visit_scopes(ScopeSet::All(TypeNS), parent_scope, ctxt, |this, scope, _, _| { | ||
match scope { | ||
Scope::Module(module, _) => { | ||
Scope::NonGlobModule(module, _) => { | ||
this.traits_in_module(module, assoc_item, &mut found_traits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting case from the language point of view.
Typically shadowed traits do not stop being in scope.
E.g. this works
trait Tr {
fn method(&self) {}
}
impl Tr for () {}
fn main() {
trait Tr {} // no method
().method(); // the first `Tr` is still in scope despite being shadowed
}
But if a trait from a glob shadowed by something non-glob, then it is no longer a scope.
Seems like a bug, but not sure if we'll be able to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a specific test:
mod glob {
pub trait Tr {
fn method(&self) {}
}
impl Tr for () {}
}
// a: use glob::*; // ok
fn main() {
// b: use glob::*; // error
trait Tr {} // no method
().method();
}
@@ -1076,7 +1076,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |||
} | |||
} | |||
} | |||
Scope::Module(module, _) => { | |||
Scope::NonGlobModule(module, _) | Scope::GlobModule(module, _) => { | |||
this.add_module_candidates(module, &mut suggestions, filter_fn, None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add candidates twice, Scope::GlobModule
can be skipped like in #144793.
@@ -1487,9 +1487,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |||
&parent_scope, | |||
ident.span.ctxt(), | |||
|this, scope, _use_prelude, _ctxt| { | |||
let Scope::Module(m, _) = scope else { | |||
return None; | |||
let m = match scope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let m = match scope { | |
let Scope::Module(m, _) | Scope::GlobModule(module, _) = scope else { |
Thanks for the review, I'll address it tomorrow. I have a question about |
Sorry, I had to go and didn't finish the review, I'll review the remaining part tomorrow.
Yeah, the main missing part is |
struct Flags: u8 { | ||
const MACRO_RULES = 1 << 0; | ||
const NON_GLOB_MODULE = 1 << 1; | ||
const GLOB_MODULE = 1 << 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The single MODULE
flag could be kept, the new flags are used identically.
TypeNS => { | ||
ctxt.adjust(ExpnId::root()); | ||
Scope::ExternPrelude | ||
Scope::NonGlobModule(..) | Scope::GlobModule(..) if module_and_extern_prelude => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope::NonGlobModule(..) | Scope::GlobModule(..) if module_and_extern_prelude => { | |
Scope::GlobModule(..) if module_and_extern_prelude => { |
From non-glob module we go to glob module, not to extern prelude.
Splits
Scope::Module
intoScope::NonGlobModule
andScope::GlobModule
. This makes it easier to implement the open namespaces project, where we have to introduce a third scope. Introducing two separate scopes for a module was also a change requested by @petrochenkov, and should make it easier to output better diagnostics.r? @petrochenkov